﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;

namespace Mysoft.MyCM.Web.Controllers
{
	/// <summary>
	/// 功能页面控制器基类
	/// 包含用户校验，选择客户校验
	/// </summary>
	[MAuthorizationFilter(MRequestType.ViewPage, MValidateType.Validate)]
	[MHandleExceptionFilter(MRequestType.ViewPage)]
	public abstract class MFunViewBaseController : MBaseController
	{
		protected override void OnActionExecuted(ActionExecutedContext filterContext)
		{
			this.UpdateVisitHistory();
			base.OnActionExecuted(filterContext);
		}

		/// <summary>
		/// 记录客户访问记录
		/// </summary>
		protected void UpdateVisitHistory()
		{
			if (string.IsNullOrEmpty(this.RequestParam.SelectedCustomerCode)) return;
			// 异步提交历史记录
			Task tVisit = new Task(new Action(() =>
			{
				try
				{
					Business.Scm.CustomBLL cstBll = new Business.Scm.CustomBLL();
					Scm.Visit visit = new Scm.Visit();
					visit.VisitGUID = Guid.NewGuid();
					visit.UserCode = this.RequestParam.LogonUser.Code;
					visit.CustomGUID = cstBll.GetGuid(this.RequestParam.SelectedCustomerCode);
					visit.VisitDate = DateTime.Now;

					Business.Scm.VisitBLL bll = new Business.Scm.VisitBLL();
					bll.UpdateVisit(visit);
				}
				catch { }
			}));
			tVisit.Start();
		}
	}
}